#include <algorithm>
#include <cstdio>

const int N = 5e3 + 5;
int T[N * N], P[N * N], L[N], R[N];
int n, m, q, mul;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P2354 [NOI2014]随机数生成器.in", "r", stdin);
  freopen("P2354 [NOI2014]随机数生成器.out", "w", stdout);
#endif
#endif

  int a, b, c, d, x;
  scanf("%d%d%d%d%d%d%d%d", &x, &a, &b, &c, &d, &n, &m, &q);
  mul = n * m;
  for (int *i = P + 1, *end = P + mul + 1, _i(1); i != end; ++i, ++_i)
    T[_i] = _i, x = *i = ((1ll * a * x % d + b) * x + c) % d;
  for (int i = 1; i <= mul; ++i) std::swap(T[P[i] % i + 1], T[i]);
  for (int i = 0, u, v; i < q; ++i)
    scanf("%d%d", &u, &v), std::swap(T[u], T[v]);
  for (int i = 1; i <= mul; ++i) P[T[i]] = i;
  for (int i = 1; i <= n; ++i) L[i] = 1, R[i] = m;
  for (int i = 1, y; i <= mul; ++i) {
    x = (P[i] + m - 1) / m, y = P[i] - (x - 1) * m;
    if (L[x] <= y && y <= R[x]) {
      printf("%d ", i);
      for (int k = x - 1; k; --k) {
        if (y < R[k]) R[k] = y;
        else
          break;
      }
      for (int k = x + 1; k <= n; ++k) {
        if (y > L[k]) L[k] = y;
        else
          break;
      }
    }
  }
  return 0;
}